<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { User, Lock } from '@element-plus/icons-vue'

const router = useRouter()

const loginForm = ref({
  username: '',
  password: ''
})

const loginFormRef = ref()

const rules = ref({
  username: [
    { required: true, message: '请输入账号', trigger: 'blur' },
    { min: 3, max: 20, message: '账号长度应在 3 到 20 个字符之间', trigger: 'blur' }
  ],
  password: [
    { required: true, message: '请输入密码', trigger: 'blur' },
    { min: 6, max: 20, message: '密码长度应在 6 到 20 个字符之间', trigger: 'blur' }
  ]
})

const rememberPassword = ref(false)

const handleLogin = () => {
  // 这里添加实际的登录逻辑
  if (loginForm.value.username && loginForm.value.password) {
    // 模拟登录成功
    localStorage.setItem('token', 'dummy-token')
    ElMessage.success('登录成功')
    // 登录成功后跳转到首页（dashboard）
    router.push('/dashboard')
  } else {
    ElMessage.error('请输入用户名和密码')
  }
}
</script>

<template>
  <div class="login-container">
    <div class="login-box">
      <div class="login-header">
        <img src="../assets/logo/轩宝阁 - 副本.png" alt="logo" class="logo">
        <h2 class="system-title">轩宝阁后台管理系统</h2>
      </div>
      
      <el-form
        ref="loginFormRef"
        :model="loginForm"
        :rules="rules"
        class="login-form"
      >
        <el-form-item prop="username">
          <el-input
            v-model="loginForm.username"
            placeholder="请输入账号"
            :prefix-icon="User"
          />
        </el-form-item>
        
        <el-form-item prop="password">
          <el-input
            v-model="loginForm.password"
            type="password"
            placeholder="请输入密码"
            :prefix-icon="Lock"
            show-password
            @keyup.enter="handleLogin"
          />
        </el-form-item>
        
        <el-form-item>
          <el-checkbox v-model="rememberPassword">记住密码</el-checkbox>
          <el-link type="primary" class="forget-pwd">忘记密码？</el-link>
        </el-form-item>
        
        <el-form-item>
          <el-button
            type="primary"
            class="login-button"
            @click="handleLogin"
          >
            登录
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<style scoped>
.login-container {
  height: 100vh;
  width: 100%;
  background: linear-gradient(135deg, #2c3e50 0%, #3498db 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

.login-box {
  width: 400px;
  padding: 40px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  position: relative;
  z-index: 1;
}

.login-header {
  text-align: center;
  margin-bottom: 40px;
}

.logo {
  width: 84px;
  height: 84px;
  margin-bottom: 20px;
  object-fit: contain;
}

.system-title {
  font-size: 24px;
  color: #303133;
  margin: 0;
  font-family: "Microsoft YaHei", "微软雅黑", sans-serif;
  font-weight: 600;
  background: linear-gradient(to right, #2c3e50, #3498db);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  letter-spacing: 2px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.login-form {
  margin-top: 30px;
}

.login-button {
  width: 100%;
  height: 40px;
  font-size: 16px;
}

.forget-pwd {
  float: right;
}

:deep(.el-input__wrapper) {
  padding-left: 11px;
}

:deep(.el-input__inner) {
  height: 40px;
}
</style> 